<?php
class Zend_View_Helper_LoggedInUser {
	protected $view;
	
	function setView($view) {
		$this->view = $view;
	}
	
	function loggedInUser() {
		$auth = Zend_Auth::getInstance();
		
		$html = '<div id="right-menu" class="main-menu">';
		$html .= '<ul>';
		
		if ($auth->hasIdentity()) {
			$changeMailUrl = $this->view->url(
					array('controller'=>'user', 'action'=>'change-mail'));
			$changePassUrl = $this->view->url(
					array('controller'=>'user', 'action'=>'change-pass'));
			$logoutUrl = $this->view->url(
					array('controller'=>'auth', 'action'=>'logout'));
			
			$user = $auth->getIdentity();
			$username = $this->view->escape($user->username);
			
			$html .= '<li><span>Logged in as ' . $username . '</span></li>';
			$html .= '<li><a href="#">My Account</a>';
			$html .= '<ul>';
			$html .= '<li><a href="'. $changeMailUrl .'">Change Email</a></li>';
			$html .= '<li><a href="'. $changePassUrl .'">Change Password</a></li>';
			$html .= '<li><a href="'. $logoutUrl . '">Logout</a></li>';
			$html .= '</ul>';
			$html .= '</li>';
		} else {
			$loginUrl = $this->view->url(
					array('controller'=>'auth', 'action'=>'form'));
			$html .= '<li><a href="' . $loginUrl . '">Log in</a></li>';
		}
		
		$html .= '</ul>';
		$html .= '</div>';
		
		return $html;
	}
}